HA$PBExportHeader$u_cst_mlistaprecio_cabedet.sru
forward
global type u_cst_mlistaprecio_cabedet from u_cst_mantocabedet
end type
end forward

global type u_cst_mlistaprecio_cabedet from u_cst_mantocabedet
end type
global u_cst_mlistaprecio_cabedet u_cst_mlistaprecio_cabedet

type variables
integer ii_tipoitem
end variables

on u_cst_mlistaprecio_cabedet.create
int iCurrent
call super::create
end on

on u_cst_mlistaprecio_cabedet.destroy
call super::destroy
end on

event ue_nuevo;call super::ue_nuevo;long ll_lista
ll_lista=0
sqlca.Usp_GetIdTablaINT(is_tabla,ll_lista)

dw_1.object.idlista[1]=ll_lista
dw_1.object.iduser[1]=gs_iduser

f_protegercolumna(1,dw_1,'idtipoitem')
end event

event constructor;string ls_dw3,ls_dw2,ls_opc,ls_dw,ls_user
long ll_codigo

istr_parm = message.powerobjectparm 

uo_toolbarstrip.visible = false
dw_1.visible = false
of_getwindow()

ids_datastore   = istr_parm.ads_menu //aqui recupera el datastore
uo_powerdock = istr_parm.auo_powerdock 
is_button         = istr_parm.as_button
ls_dw              = ids_datastore.object.tDw1[1]
ls_dw2              = ids_datastore.object.tDw2[1]
is_tabla           = ids_datastore.object.tTabla[1]
is_window  					   = ids_datastore.object.twindow[1]
ii_window  					   = ids_datastore.object.bwindow[1]

is_entidad = ids_datastore.object.tEntidad[1]
if isnull(is_entidad) then is_entidad=''
iuo_tab            = istr_parm.auo_userobject 
iuo_grillamain  = istr_parm.auo_grillamaincabedet
iuo_tabmantomain = istr_parm.auo_tabmantocabedet
is_idcodigo			=  istr_parm.as_parm[1] //id tabla
if ls_dw = '' or isnull(ls_dw) then return

dw_1.dataobject=ls_dw //cabecera
dw_3.dataobject=ls_dw2//detalle
dw_1.settransobject(sqlca)
dw_3.settransobject(sqlca)
dw_2.dataobject=ls_dw
dw_4.dataobject=ls_dw2
//limpiar
dw_1.reset();dw_3.reset()
dw_2.reset();dw_4.reset()
st_titulo.text = ids_datastore.object.tTitulo[1]
st_det1.text = ids_datastore.object.tObse1[1]
st_det2.text = ids_datastore.object.tObse2[1]
il_error =0
//uo_1.of_BackColor2(of_GetColor("BACKGROUND2"))
uo_1.of_BackColor2(RGB(129,169,226))
f_dataload('MITEM')
//event post ue_settabtext ('')
//EVENT ue_mostrar (istr_parm,true,0)



end event

event ue_agregar;
integer li_row
string ls_criterio
datetime ld_fecha
decimal{2} ld_igv 
if dw_1.accepttext( )= -1 Then Return
If f_findrequired(dw_1) = -1 Then Return 

ii_tipoitem  = dw_1.object.idtipoitem[1]
li_row =  dw_3.rowcount() 
dw_3.scrolltorow(dw_3.insertrow( 0))
if li_row = 0 then
	dw_3.object.idindice [1]=	1
else
	dw_3.object.idindice [dw_3.rowcount()]=	dw_3.object.idindice [li_row]+1
end if

//dw_3.GetChild("iditem", dwc);dwc.reset()
//gdc_mitem1.RowsCopy(gdc_mitem1.GetRow(), gdc_mitem1.RowCount(), Primary!, dwc, 1, Primary!)

ls_criterio="string(idtipoitem)= '"+string(ii_tipoitem)+"'"
f_filtrar_item('MITEM',dw_3,dwc,dwc2,ls_criterio)

f_protegercolumna(0,dw_1,'idtipoitem')
ld_fecha =datetime(date(today()),time(now()))
ld_igv = 19
sqlca.Usp_GetIGV(ld_fecha,ld_igv)

dw_3.object.idlista [dw_3.rowcount()]=dw_1.object.idlista[1]
dw_3.object.idmoneda [dw_3.rowcount()]=dw_1.object.idmoneda[1]
dw_3.object.nporc1 [dw_3.rowcount()] = ld_igv





end event

event ue_eliminar_detalle;integer li_fila
if dw_3.rowcount() = 0 then return
if f_msg('Esta seguro que desea eliminar este registro ??' + string(dw_3.getrow()), 2) = 2 then return 
dw_3.deleterow(0)
if dw_3.rowcount() = 0 then
	f_protegercolumna(80,dw_1,'idtipoitem')	
end if

end event

event ue_sumar;integer li_fila
double ld_preciobase,ld_totalDocu
ld_totalDocu = 0 

for li_fila = 1 to dw_3.rowcount( )
	ld_preciobase = dw_3.Object.nprecioventa[li_fila]
	if dw_3.Object.nexoigv[li_fila] =1 then
		dw_3.Object.nprecioneto[li_fila] =ld_preciobase
		dw_3.Object.nimpuesto1[li_fila] =  0
		dw_3.Object.nporc1[li_fila] =0
	else
		if dw_3.Object.nporc1[li_fila]  > 0 then
			dw_3.Object.nprecioneto[li_fila] = ld_preciobase / (1 +(dw_3.Object.nporc1[li_fila] /100))
			dw_3.Object.nimpuesto1[li_fila] =  ld_preciobase - dw_3.Object.nprecioneto[li_fila] 
		end if
	end if
		
	if dw_3.Object.nprecioventamin[li_fila] = 0 then dw_3.Object.nprecioventamin[li_fila] = ld_preciobase
	if dw_3.Object.nprecioventamax[li_fila] = 0 then dw_3.Object.nprecioventamax[li_fila] = ld_preciobase

next



end event

event ue_grabar_previo;long ll_lista
integer li_fila

CHOOSE CASE UPPER(is_button)
	case 'NUEVO'
		ll_lista=0
		sqlca.Usp_GetIdTablaINT(is_tabla,ll_lista)
		event ue_sumar()
	case 'EDITAR'
		//event ue_sumar()
END CHOOSE
end event

event ue_editar;call super::ue_editar;f_protegercolumna(0,dw_1,'idtipoitem')
end event

event ue_setdwc;dw_2.GetChild("idtipoitem", dwc);dwc.reset();	dwc.settransobject( sqlca);	dwc.retrieve( )
end event

event ue_cambio_opc;string ssas_button


choose case upper(as_button) 
	case 'NUEVO'
		uo_toolbarstrip.visible = TRUE
		uo_toolbarstrip.of_setvisible( 'Editar', FALSE);
		//uo_toolbarstrip.of_setvisible( 'Anular', FALSE)
		uo_toolbarstrip.of_setvisible( 'Grabar', TRUE)// ; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', TRUE)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', TRUE)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', TRUE)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
		dw_1.visible = TRUE ; 		dw_3.visible = TRUE ; 	dw_2.visible =FALSE; 		dw_4.visible =FALSE
		dw_1.enabled = true ; dw_3.enabled=true
		event ue_settabtext( 'NUEVO')
	case 'EDITAR'
		uo_toolbarstrip.visible = TRUE
		dw_1.enabled = true ; dw_3.enabled=true
		dw_1.visible = true ; 		dw_3.visible = true ; 	dw_2.visible =false; 		dw_4.visible =false
		uo_toolbarstrip.of_setvisible( 'Editar', false);
		uo_toolbarstrip.of_setvisible( 'Anular', false)
		uo_toolbarstrip.of_setvisible( 'Grabar', true) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', true)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', true)//; uo_toolbarstrip.of_setenabled( 'Agregar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', true)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', ab_ver)
		event ue_settabtext( 'EDITAR')
	case 'ANULAR'
		uo_toolbarstrip.visible = TRUE
		dw_1.enabled = false ; dw_3.enabled=false
		dw_1.visible = true ; 		dw_3.visible = true ; 	dw_2.visible =false; 		dw_4.visible =false
		uo_toolbarstrip.of_setvisible( 'Editar', false);
		//uo_toolbarstrip.of_setvisible( 'Anular', false)
		uo_toolbarstrip.of_setvisible( 'Grabar', true) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		uo_toolbarstrip.of_setvisible( 'Cancelar', true)//;uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Agregar', false)//; uo_toolbarstrip.of_setenabled( 'Agregar', ab_ver)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', false)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', ab_ver)
	case 'CANCELAR'	
		dw_1.enabled = false ; dw_3.enabled=false
		uo_toolbarstrip.of_setvisible( 'Grabar', FALSE) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		dw_1.visible = FALSE ; 		dw_3.visible = FALSE ; 	dw_2.visible = TRUE; 		dw_4.visible =TRUE
		uo_toolbarstrip.of_setvisible( 'Cancelar', false)
		uo_toolbarstrip.of_setvisible( 'Editar', true);
		//uo_toolbarstrip.of_setvisible( 'Anular', TRUE)
		uo_toolbarstrip.of_setvisible( 'Agregar', FALSE)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', FALSE)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
		event ue_settabtext( 'Consultar')
	CASE 'CONSULTAR'
		dw_1.visible = FALSE ; 		dw_3.visible = FALSE ; 	dw_2.visible = TRUE; 		dw_4.visible =TRUE
		dw_1.enabled = false; dw_2.enabled = false
		uo_toolbarstrip.visible = TRUE
		uo_toolbarstrip.of_setvisible( 'Grabar', FALSE) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
		dw_1.visible = FALSE ; 		dw_3.visible = FALSE ; 	dw_2.visible = TRUE; 		dw_4.visible =TRUE
		uo_toolbarstrip.of_setvisible( 'Cancelar', FALSE)
		uo_toolbarstrip.of_setvisible( 'Editar', true);
		uo_toolbarstrip.of_setvisible( 'Anular', true)
		uo_toolbarstrip.of_setvisible( 'Agregar', FALSE)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', FALSE)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
	CASE 'DEFAULT'
		dw_1.enabled= false ;	dw_1.visible = false ;		dw_2.visible = false ;		uo_1.visible = true
		uo_toolbarstrip.visible = false ;		st_titulo.visible = true ;		st_det1.visible = true
		event ue_settabtext( 'PRINCIPAL')
	case	else 
//		uo_toolbarstrip.of_setvisible( 'Grabar', lb_sw) //; uo_toolbarstrip.of_setenabled( 'Grabar', ab_ver)	
//		dw_1.visible = lb_sw ; 		dw_3.visible = lb_sw ; 	dw_2.visible = ab_ver; 		dw_4.visible =ab_ver
//		uo_toolbarstrip.of_setvisible( 'Cancelar', lb_sw)
//		uo_toolbarstrip.of_setvisible( 'Editar', ab_ver);
//		uo_toolbarstrip.of_setvisible( 'Anular', ab_ver)
//		uo_toolbarstrip.of_setvisible( 'Agregar', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Agregar', lb_sw)
//		uo_toolbarstrip.of_setvisible( 'Eliminar Fila', lb_sw)//; uo_toolbarstrip.of_setenabled( 'Eliminar Fila', lb_sw)
end choose

end event

event ue_copy_fila_det;long ll_rows
INTEGER LI_ROW
dw_3.reset()
dw_4.reset(); dw_3.clear();dw_4.clear()
ii_sw =ai_sw
//ii_row  = ai_row

if ad_dw.rowcount() > 0 then
	dw_4.object.data = ad_dw.object.data
	dw_4.GetChild("iditem", dwc);dwc.reset()
	gdc_mitem1.RowsCopy(gdc_mitem1.GetRow(), gdc_mitem1.RowCount(), Primary!, dwc, 1, Primary!)
end if
event ue_setdwc()	
end event

event ue_grabar_pos;//dw_4.GetChild("iditem", dwc);dwc.reset()
//gdc_mitemalma1.RowsCopy(gdc_mitemalma1.GetRow(), gdc_mitemalma1.RowCount(), Primary!, dwc, 1, Primary!)
////dw_1.reset();dw_3.reset( )
iuo_grillamain.event ue_activa_opc( false)
this.event ue_cambio_opc('Consultar')
this.event ue_settabtext( 'Consultar')

dw_1.reset();dw_3.reset( )
iuo_grillamain.event dynamic ue_activa_opc(false) 
iuo_grillamain.event dynamic ue_bloquear_refrescar(false) 
this.event ue_setdwc()
end event

type dw_5 from u_cst_mantocabedet`dw_5 within u_cst_mlistaprecio_cabedet
end type

type dw_4 from u_cst_mantocabedet`dw_4 within u_cst_mlistaprecio_cabedet
string dataobject = "d_mlistapreciod_tabular"
end type

type dw_3 from u_cst_mantocabedet`dw_3 within u_cst_mlistaprecio_cabedet
end type

event dw_3::itemchanged;call super::itemchanged;Choose Case dwo.name
	Case 'iditem'
	
	case 'nprecioventa','nporc1'
		if double (data)> 0 then post event ue_updaterow( row)
END CHOOSE
end event

event dw_3::ue_updaterow;call super::ue_updaterow;double ld_preciobase 

ld_preciobase = dw_3.Object.nprecioventa[ai_fila]
if dw_3.Object.nexoigv[ai_fila] =1 then
	dw_3.Object.nprecioneto[ai_fila] =ld_preciobase
	dw_3.Object.nimpuesto1[ai_fila] =  0
	dw_3.Object.nporc1[ai_fila] =0
else
	if dw_3.Object.nporc1[ai_fila]  > 0 then
		dw_3.Object.nprecioneto[ai_fila] = ld_preciobase / (1 +(dw_3.Object.nporc1[ai_fila] /100))
		dw_3.Object.nimpuesto1[ai_fila] =  ld_preciobase - dw_3.Object.nprecioneto[ai_fila] 
	end if
end if
	
if dw_3.Object.nprecioventamin[ai_fila] = 0 then dw_3.Object.nprecioventamin[ai_fila] = ld_preciobase
if dw_3.Object.nprecioventamax[ai_fila] = 0 then dw_3.Object.nprecioventamax[ai_fila] = ld_preciobase
end event

type st_det2 from u_cst_mantocabedet`st_det2 within u_cst_mlistaprecio_cabedet
end type

type st_det1 from u_cst_mantocabedet`st_det1 within u_cst_mlistaprecio_cabedet
end type

type st_titulo from u_cst_mantocabedet`st_titulo within u_cst_mlistaprecio_cabedet
end type

type dw_2 from u_cst_mantocabedet`dw_2 within u_cst_mlistaprecio_cabedet
string dataobject = "d_mlistaprecio_free"
end type

type uo_toolbarstrip from u_cst_mantocabedet`uo_toolbarstrip within u_cst_mlistaprecio_cabedet
end type

event uo_toolbarstrip::constructor;this.of_AddItem('Grabar', 'Save!')
this.of_AddItem('Editar', gs_unidad+'\IMG\ICO\edit.ico')
//this.of_AddItem('Anular', gs_unidad+'\IMG\ICO\Error.ico')
this.of_AddItem('Agregar', 'Insert5!')
this.of_AddItem('Eliminar Fila', 'DeleteRow!')
this.of_AddItem('Cancelar', 'Undo!')
this.of_AddItem('Imprimir', 'Print!')

//opciones en estado invisible
this.of_setvisible( 'Grabar', false)
this.of_setvisible( 'Agregar', false)
this.of_setvisible( 'Eliminar Fila', false)
this.of_setvisible( 'Cancelar', false)
this.of_setvisible('Imprimir', false)
//esto es para mostar los textos
this.of_DisplayText(true)


end event

type dw_1 from u_cst_mantocabedet`dw_1 within u_cst_mlistaprecio_cabedet
end type

type uo_1 from u_cst_mantocabedet`uo_1 within u_cst_mlistaprecio_cabedet
end type

